package prototype;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

public class ScheduleView extends JFrame {

    private JButton btnWeeklyUsage;
    private JButton dailyUsage;

    public ScheduleView() {
        getContentPane().setBackground(Color.WHITE);

        String[] columnNames = {"Appliance", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
        String[][] scheduleData = {
                {"Dishwasher", "6:00pm", "", "", "8:00pm", "", "3:00pm", ""},
                {"Oven/Stove", "7:00pm", "8:00pm", "7:30pm", "6:00pm", "6:30pm", "6:00pm", "6:45pm"},
                {"Washing Machine", "", "", "", "", "", "12:00pm", ""},
                {"Dryer", "", "", "", "", "", "1:00pm", ""},
        };

        getContentPane().setLayout(new BorderLayout());
        JLabel txtpnSchedule = new JLabel("Schedule", JLabel.CENTER);
        txtpnSchedule.setFont(new Font("Tahoma", Font.BOLD, 24));
        getContentPane().add(txtpnSchedule, BorderLayout.NORTH);

        JTable schedule = new JTable(scheduleData, columnNames);
        schedule.setRowHeight(50);
        schedule.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        schedule.setRowSelectionAllowed(false);
        schedule.setColumnSelectionAllowed(false);

        DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
        centerRenderer.setHorizontalAlignment(JLabel.CENTER);
        for (int i=0; i<schedule.getColumnCount(); i++)
            schedule.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
        schedule.getTableHeader().setDefaultRenderer(centerRenderer);

        JScrollPane scrollPane = new JScrollPane(schedule);
        getContentPane().add(scrollPane, BorderLayout.CENTER);

        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{490, 60, 30, 120, 0};
        JPanel panel = new JPanel(gridBagLayout);

        btnWeeklyUsage = new JButton("Weekly Usage");
        GridBagConstraints gbc_btnWeeklyUsage = new GridBagConstraints();
        gbc_btnWeeklyUsage.insets = new Insets(0, 0, 5, 5);
        gbc_btnWeeklyUsage.anchor = GridBagConstraints.CENTER;
        gbc_btnWeeklyUsage.gridx = 1;
        gbc_btnWeeklyUsage.gridy = 0;
        panel.add(btnWeeklyUsage, gbc_btnWeeklyUsage);

        dailyUsage = new JButton("Daily Usage");
        GridBagConstraints gbc_btnDailyUsage = new GridBagConstraints();
        gbc_btnDailyUsage.insets = new Insets(0, 0, 5, 5);
        gbc_btnDailyUsage.anchor = GridBagConstraints.CENTER;
        gbc_btnDailyUsage.gridx = 2;
        gbc_btnDailyUsage.gridy = 0;
        panel.add(dailyUsage, gbc_btnDailyUsage);

        getContentPane().add(panel, BorderLayout.SOUTH);
    }

    public JButton getBtnWeeklyUsage() {
        return btnWeeklyUsage;
    }

    public JButton getDailyUsage() {
        return dailyUsage;
    }
}
